package demo;

import com.lijinjiang.beautyeye.BeautyEyeLNFHelper;
import com.lijinjiang.beautyeye.ch3_button.BEButtonUI;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @ClassName demo.JButtonDemo
 * @Description TODO
 * @Author Li
 * @Date 2022/8/27 14:11
 * @ModifyDate 2022/8/27 14:11
 * @Version 1.0
 */
public class JDialogDemo extends JFrame{

    public JDialogDemo() {
        this.setTitle("demo.JButtonDemo"); // 设置窗口标题
        this.setSize(400, 360); // 设置窗口显示大小-
        JPanel panel = new JPanel();
        panel.setLayout(null);
        /* 1.消息对话框（提示消息） */
        JButton button1 = new JButton("showMessageDialog(提示)");
        button1.setBounds(100, 20, 180, 30);
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(JDialogDemo.this, "这是一条提示信息",
                        "标题1", JOptionPane.INFORMATION_MESSAGE);
            }
        });

        /* 2.消息对话框（警告消息） */
        JButton button2 = new JButton("showMessageDialog(警告)");
        button2.setBounds(100, 70, 180, 30);
        button2.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.green));
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(JDialogDemo.this, "警告！警告！",
                        "标题2", JOptionPane.WARNING_MESSAGE);
            }
        });

        /* 3.确认对话框 */
        JButton button3 = new JButton("showConfirmDialog");
        button3.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.lightBlue));
        button3.setBounds(100, 120, 180, 30);
        button3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int res = JOptionPane.showConfirmDialog(JDialogDemo.this, "确认要删除？",
                        "标题3", JOptionPane.YES_NO_OPTION,JOptionPane.PLAIN_MESSAGE,null);
                System.out.println("选择的结果：" + res);
            }
        });

        /* 4.输入对话框（文本输入） */
        JButton button4 = new JButton("showInputDialog(输入)");
        button4.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.red));
        button4.setBounds(100, 170, 180, 30);
        button4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String input = JOptionPane.showInputDialog(JDialogDemo.this, "请输入访问密码",
                        "标题4", JOptionPane.WARNING_MESSAGE);
                System.out.println("输入的内容：" + input);
            }
        });

        /* 5.输入对话框（下拉框选择） */
        JButton button5 = new JButton("showInputDialog(下拉)");
        button5.setUI(new BEButtonUI().setNormalColor(BEButtonUI.NormalColor.blue));
        button5.setBounds(100, 220, 180, 30);
        button5.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Object[] selectValues = new Object[]{"春季","夏季","秋季","冬季"};
                Object value = JOptionPane.showInputDialog(JDialogDemo.this, "请选择最喜欢的季节：",
                        "标题5", JOptionPane.PLAIN_MESSAGE, null, selectValues, selectValues[0]);
                System.out.println("选择的内容：" + value);
            }
        });

        /* 6.选项对话框 */
        JButton button6 = new JButton("showOptionDialog");
        button6.setBounds(100, 270, 180, 30);
        button6.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Object[] options = new Object[]{"上午","下午"};
                int optionSelected = JOptionPane.showOptionDialog(JDialogDemo.this, "请选择合适的时间",
                        "标题6", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE,
                        null, options, options[0]);
                if (optionSelected >=0){
                    System.out.println("选择的按钮：" + options[optionSelected]);
                }
            }
        });

        panel.add(button1);
        panel.add(button2);
        panel.add(button3);
        panel.add(button4);
        panel.add(button5);
        panel.add(button6);
        this.add(panel);
        //this.setIconImage(ImageUtil.LOGO_ICON); // 设置窗口图标
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设置窗口默认关闭操作
        this.setLocationRelativeTo(null); // 相对屏幕居中
        this.setVisible(true); // 设置窗口可见
    }

    public static void main(String[] args) {
        try {
            BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;
            BeautyEyeLNFHelper.launchBeautyEyeLNF();
        } catch (Exception e) {
        }
        new JDialogDemo();
    }
}
